<?php

namespace mpend\modules\cms\models;

use Yii;
use common\models\cms\CmsArticleShield;

/**
 * 收藏、取消收藏动态模型
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class ArticleShieldForm extends \common\base\Model {

    /**
     * @var integer 用户UID
     */
    public $user_id;

    /**
     * @var integer 文章ID
     */
    public $article_id;

    /**
     * @return array validation rules
     */
    public function rules() {
        return [
            [['user_id', 'article_id'], 'integer'],
            [['article_id'], 'required'],
        ];
    }

    /**
     * 保存屏蔽记录信息
     * @return boolean
     */
    public function save() {
        if (!$this->validate()) {
            return $this->dumpError('屏蔽失败');
        }
        $model = CmsArticleShield::findOrNew([
            'article_id' => $this->article_id,
            'user_id' => $this->user_id,
        ]);
        return $model->save();
    }

}
